package com.minelx.sqlstructures.statements.clause;

import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.unmodifiableList;

public class AndBuilder {
	private final List<String> conditions;

	private AndBuilder(List<String> conditions) {
		this.conditions = conditions;
	}

	public AndBuilder add(String added) {
		if (!added.isEmpty()) {
			conditions.add(added);
		}
		return this;
	}

	public String build() {
		return String.join(" AND ", conditions);
	}

	public void remove(String which) {
		conditions.remove(which);
	}

	public void remove(int index) {
		conditions.remove(index);
	}

	public void removeAll() {
		conditions.clear();
	}

	public void addAll(List<String> added) {
		conditions.addAll(added);
	}

	public List<String> conditions() {
		return unmodifiableList(conditions);
	}

	public AndBuilder copy() {
		return create(new ArrayList<>(conditions));
	}

	public static AndBuilder empty() {
		return create(new ArrayList<>());
	}

	public static AndBuilder create(List<String> conditions) {
		return new AndBuilder(conditions);
	}
}
